﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Gencode.PrsCommon.Data.Dienst;

namespace Gencode.PrsUtil.Controls
{
	public class PUDienstSchemaGrid : Gencode.Gengui.GUGrid
	{
		private System.Windows.Forms.DataGridViewTextBoxColumn dienstid;
		private System.Windows.Forms.DataGridViewTextBoxColumn name;
		private System.Windows.Forms.DataGridViewTextBoxColumn einsatz;
		private DataView m_data;

		public PUDienstSchemaGrid()
		{
			InitializeComponents();
		}

		private void InitializeComponents()
		{
			this.dienstid = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.name = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.einsatz = new System.Windows.Forms.DataGridViewTextBoxColumn();

			((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
			this.SuspendLayout();

			this.Columns.Clear();
			this.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.dienstid,
            this.name,
            this.einsatz});

			this.dienstid.HeaderText = "id";
			this.dienstid.Name = "dienstid";
			this.dienstid.Width = 40;
			// 
			// name
			// 
			this.name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.name.HeaderText = "Name";
			this.name.Name = "name";
			// 
			// einsatz
			// 
			this.einsatz.HeaderText = "Einsätze";
			this.einsatz.Name = "einsatz";
			this.einsatz.Width = 72;

			((System.ComponentModel.ISupportInitialize)(this)).EndInit();
			this.ResumeLayout(false);
		}

		public void InitData(int schemaid, int abteilungid, bool zugewiesen)
		{
			if (zugewiesen)
			{
				m_data = DienstData.GetDienstSchema(schemaid, abteilungid, "");
			}
			else
			{
				m_data = DienstData.GetDienstNotInSchema(schemaid, abteilungid);
			}

			AutoGenerateColumns = false;

			DataSource = m_data;

			Columns["dienstid"].DataPropertyName = "dienstid";
			Columns["name"].DataPropertyName = "dienstname";
			Columns["einsatz"].DataPropertyName = "einsatzprotag";
		}
	}
}
